<template>
  <div id="flight-orders" class="card col-12 px-0 mt-5">
    <nav aria-label="breadcrumb" role="navigation">
      <ol class="breadcrumb pb-0">
        <li class="breadcrumb-item active ms-1" aria-current="page">
          机票订单
        </li>
        <li class="breadcrumb-item ms-auto me-1">
          <router-link to="/h5/flt/search">国内查询</router-link>
        </li>
      </ol>
    </nav>
    <div class="card-header" v-show="searchOption === false">
      <router-link class="btn btn-success ms-auto" to="/h5/new/flt/order"
        >新建</router-link
      >
      <button
        type="button"
        class="btn btn-primary float-end"
        @click.stop="showSearchOption()"
      >
        查找
      </button>
    </div>
    <div class="card-body" v-show="searchOption">
      <form>
        <div class="row mb-2">
          <input
            type="textfield"
            class="form-control form-control-sm"
            size="6"
            placeholder="姓名"
            v-model.trim="name"
          />
        </div>
        <div class="row mb-2">
          <input
            type="textfield"
            class="form-control form-control-sm"
            size="10"
            placeholder="航班号"
            v-model.trim="flightNo"
          />
        </div>
        <div class="row mb-2">
          <input
            type="textfield"
            class="form-control form-control-sm"
            size="6"
            placeholder="证件号"
            v-model.trim="idno"
          />
        </div>
        <div class="row mb-2">
          <input
            type="textfield"
            class="form-control form-control-sm"
            size="12"
            placeholder="票号"
            v-model.trim="ticketNo"
          />
        </div>
        <div class="row mb-2">
          <input
            type="textfield"
            class="form-control form-control-sm"
            size="6"
            placeholder="编码"
            v-model.trim="pnrNo"
          />
        </div>
        <div class="row mb-2">
          <input
            type="textfield"
            class="form-control form-control-sm"
            size="6"
            placeholder="订单号"
            v-model.trim="orderNo"
          />
        </div>
        <div class="row mb-2">
          <my-date-picker
            id="ddate"
            v-model="ddate"
            placeholder="航班日期"
            sizing="sm"
          ></my-date-picker>
        </div>
        <div class="row mb-2">
          <my-date-picker
            id="beginDate"
            name="sc.beginDate"
            v-model="beginDate"
            placeholder="开始日期"
            sizing="sm"
          ></my-date-picker>
        </div>
        <div class="row mb-2">
          <my-date-picker
            id="endDate"
            name="sc.endDate"
            v-model="endDate"
            placeholder="截止日期"
            sizing="sm"
          ></my-date-picker>
        </div>
        <div class="row mb-2">
          <select
            class="form-select form-control-sm"
            v-model.number="status"
            name="sc.status"
          >
            <option value="-1">所有状态</option>
            <option value="0">暂不开票</option>
            <option value="1">待开票审核</option>
            <option value="2">待开票</option>
            <option value="4">已取消</option>
            <option value="8">开票中</option>
            <option value="16">已开票</option>
            <option value="32">已完成</option>
          </select>
        </div>
        <button
          type="button"
          class="btn btn-primary ms-auto"
          @click.stop="search()"
        >
          确定
        </button>
        <button type="button" class="btn btn-sm ms-auto" @click.stop="reset()">
          重置
        </button>
      </form>
    </div>
    <template v-if="searchOption === false">
      <flight-order-list :dataList="dataList"></flight-order-list>
      <nav id="pagination-box" class="float-end">
        <my-pagination
          name="pagination"
          :row-count="sc.rowCount"
          :page-total="sc.pageTotal"
          :page-no="sc.pageNo"
          @next-page="nextPage"
          @prev-page="prevPage"
          @direct-page="directPage"
        ></my-pagination>
      </nav>
    </template>
  </div>
</template>

<script>
import { searchFlightOrders } from "@/api/flight.js";
import MyDatePicker from "@/components/my-datepicker.vue";
import MyPagination from "@/components/my-pagination_h5.vue";
import FlightOrderList from "@/components/list/flight-order-list_h5.vue";

export default {
  name: "MyFlightOrders",
  components: {
    MyDatePicker,
    MyPagination,
    FlightOrderList
  },
  data() {
    return {
      dataList: [],

      sc: {
        rowCount: 0,
        pageNo: 1,
        pageSize: 10,
        pageTotal: 0,
      },

      beginDate: "",
      endDate: "",
      name: "",
      idno: "",
      ticketNo: "",
      pnrNo: "",
      status: -1,
      customerId: -1,
      customerType: -1,
      intlTicket: -1,
      workStatus: 0,
      onlyMine: 0,
      op1: "",
      orderNo: "",
      payStatus: -1,
      flightNo: "",
      ddate: "",
      searchOption: false,
    };
  },
  mounted: function () {
    this.$store.commit("setWorkMode", "h5");
    // console.log('mounted')
  },
  activated: function () {
    this.search();
    // console.log('activated')
  },
  deactivated: function () {
    // console.log('deactivated')
  },
  methods: {
    showLoading: function (loadingText) {
      this.$store.commit("showLoading", {
        loading: true,
        loadingText: loadingText,
      });
    },
    hideLoading: function () {
      this.$store.commit("hideLoading");
    },
    showSearchOption: function () {
      this.searchOption = true;
    },
    search: function () {
      this.searchOption = false;
      const params = {
        "sc.pageNo": this.sc.pageNo,
        "sc.pageSize": this.sc.pageSize,
        "sc.beginDate": this.beginDate,
        "sc.endDate": this.endDate,
        "sc.name": this.name,
        "sc.idno": this.idno,
        "sc.status": this.status,
        "sc.customerId": this.customerId,
        "sc.customerType": this.customerType,
        "sc.ticketNo": this.ticketNo,
        "sc.intlTicket": this.intlTicket,
        "sc.pnrNo": this.pnrNo,
        "sc.workStatus": this.workStatus,
        "sc.onlyMine": this.onlyMine,
        "sc.op1": this.op1,
        "sc.orderNo": this.orderNo,
        "sc.payStatus": this.payStatus,
        "sc.departureDate": this.ddate,
        "sc.flightNo": this.flightNo,
      };
      this.showLoading("查询中");
      searchFlightOrders(
        params,
        (jsonResult) => {
          this.dataList = jsonResult.dataList;
          this.sc = jsonResult.page;
        },
        () => {
          this.hideLoading();
        }
      );
    },
    reset: function () {
      this.beginDate = "";
      this.endDate = "";
      this.name = "";
      this.idno = "";
      this.ticketNo = "";
      this.pnrNo = "";
      this.status = -1;
      this.sc.pageNo = 1;
      this.onlyMine = 0;
      this.op1 = "";
      this.orderNo = "";
      this.customerId = -1;

      this.ddate = "";
      this.flightNo = "";
      // this.search()
    },
    prevPage: function () {
      this.sc.pageNo = this.sc.pageNo - 1;
      if (this.sc.pageNo < 1) this.sc.pageNo = 1;
      this.search();
    },
    nextPage: function () {
      this.sc.pageNo = this.sc.pageNo + 1;
      this.search();
    },
    directPage: function (pageNo) {
      this.sc.pageNo = pageNo;
      this.search();
    },
  },
};
</script>